//	树型结构对象
package newXgame.utils.list.struct
{	
	public class MenuStruct extends SuperStruct
	{
		public var menuPath:String	= "";		//	菜单项地址
		
		public var subArray:Array	= new Array();		//	当前菜单的子级对象（每个子组都是一个 MenuStruct 类成员
		public var dataArray:Array	= new Array();		//	数据成员
		
		public function MenuStruct(cID:Number = 0, sID:Number = 0, pID:Number = 0, mName:String = "", mPath:String = "")
		{
			cateID = cID;
			sysID = sID;
			objID = pID;
			objName = mName;
			menuPath = mPath;
			
			subArray = new Array();
			dataArray = new Array();
		}	
		
		//	检测是否可以添加新的菜单项目
		public function AddIteam(ms:MenuStruct):Boolean
		{
			var sID:Number = ms.sysID;
			var pID:Number = ms.objID;
			
			if(sID == this.sysID)
			{
				if(pID == this.cateID)
				{
					var isFind:Boolean = false;				
					for(var m:int = 0; m < this.subArray.length; m++)
					{
						var tmp:MenuStruct = this.subArray[m];
						if(tmp.cateID == ms.cateID)
						{
							isFind = true;
							break;
						}
					}
					
					if(!isFind)
					{
						this.subArray.push(ms);
					}
					return true;
				}
				else
				{
					for(var i:int = 0; i < subArray.length; i++)
					{
						var sub:MenuStruct = subArray[i];
						if(sub.AddIteam(ms))
						{
							return true;
						}
					}		
					return false;
				}
			}
			
			return false;	
		}
		
		//	添加数据
		public function AddData(msd:MenuDataStruct):Boolean
		{
			var sID:Number = msd.sysID;
			var cID:Number = msd.cateID;
			
			if(sID == this.sysID)
			{
				if(cID == this.cateID)
				{
					var isFind:Boolean = false;				
					for(var m:int = 0; m < this.dataArray.length; m++)
					{
						var tmp:MenuDataStruct = this.dataArray[m];
						if(tmp.objID == msd.objID)
						{
							isFind = true;
							break;
						}
					}
					
					if(!isFind)
					{
						this.dataArray.push(msd);
					}
					return true;
				}
				else
				{
					for(var i:int = 0; i < subArray.length; i++)
					{
						var sub:MenuStruct = subArray[i];
						if(sub.AddData(msd))
						{
							return true;
						}
					}		
					return false;
				}
			}	
				
			return false;	
		}
		
		public function toString():String
		{
			var str:String = "cateID --> " + this.cateID + 
							"sysID --> " + this.sysID + 
							"objID --> " + this.objID +
							"objName --> " + this.objName +
							"menuPath --> " + this.menuPath;
							
			for(var i:int = 0; i < subArray.length; i++)
			{
				str += "\n sub[" + subArray.length + "] --> " + subArray[i].toString();
			}
			for(var j:int = 0; j < dataArray.length; j++)
			{
				str += "\n img[" + dataArray.length + "] --> " + dataArray[j].toString();
			}
			
			return str;
		}	
	}
}